package com.template.feature;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.template.enums.FeatureMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * @description:
 * @author: yanchao
 * @time: 2021-12-29 19:54
 */
public class PutFeature extends AbstractMethod {

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        FeatureMethod sqlMethod = FeatureMethod.PUT_FEATURE;

        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(),

                tableInfo.getKeyColumn(), tableInfo.getKeyProperty());

        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);

        return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);

    }
}
